package 优先算法.前缀和.模版二维前缀和;

import java.util.Scanner;

/**
 *
 *<a>https://www.nowcoder.com/practice/99eb8040d116414ea3296467ce81cbbc?tpId=230&tqId=2023819&ru=/exam/oj&qru=/ta/dynamic-programming/question-ranking&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D196</a>
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //1。输入数组
        int n = sc.nextInt(),m = sc.nextInt(),q = sc.nextInt();
        int[][] arr = new int[n+1][m+1];
        for(int i = 1;i <= n;i++){//行
            for(int j = 1;j <= m;j++){//列
                arr[i][j]=sc.nextInt();
            }
        }
        //2.构建前缀和数组
        long[][] dp = new long[n+1][m+1];//防止溢出！！！！！！！！！！！！！！！！！！！！
        for(int i = 1;i <= n;i++){//行
            for(int j = 1;j <= m;j++){//列
                //————————
                //|A | B |
                //————————
                //|C | D |
                //————————
                //求A+B+C+D
                //A+B + A+C + D - A
                dp[i][j]=dp[i-1][j] + dp[i][j-1] + arr[i][j] - dp[i-1][j-1];
            }
        }
        //3.使用前缀和
        while(q > 0){
            int x1 = sc.nextInt(), y1 = sc.nextInt(),x2 = sc.nextInt(),y2 = sc.nextInt();
            //————————
            //|A | B |
            //————————
            //|C | D |
            //————————
            //求D
            //A+B+C+D - (A+C) - (A+B) + A
            long rel = dp[x2][y2] - dp[x2][y1-1] - dp[x1-1][y2] + dp[x1-1][y1-1];
            System.out.println(rel);
            q--;
        }
    }
}
